﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;
namespace CungMuaC5.Account_Admin.QuanLyDDH
{
    public partial class DDH_Sua : System.Web.UI.Page
    {
        int MaDH;
        DTO_DonHang dh = new DTO_DonHang();
        protected void Page_Load(object sender, EventArgs e)
        {
            MaDH = int.Parse(Request.QueryString["ma"].ToString());
            if (!IsPostBack)
            {
                Label6.Text = "";                
                GetThongTinDH(MaDH);
            }
        }
        public void GetThongTinDH(int maDH)
        {
            BUS_DonHang bus = new BUS_DonHang();
            
            BUS_NguoiNhan busNN = new BUS_NguoiNhan();
            BUS_KhuyenMai busKM = new BUS_KhuyenMai();
            BUS_TaiKhoan busTK = new BUS_TaiKhoan();


            dh = bus.GetThongTinDH(maDH.ToString());
            Label4.Text = busNN.GetTenNN(dh.NguoiNhan);

            Label3.Text = busKM.GetTenKM(dh.KhuyenMai);

            Label5.Text = dh.NgayDatHang.ToString("hh:mm dd/mm/yyyy");
            DropDownListSoLuong.SelectedIndex = dh.SoLuong;
            TextBox7.Text = dh.PhiGiaoHang.ToString();
            DropDownList3.SelectedIndex = dh.TinhTrangThanhToan;
            DropDownList2.SelectedIndex = dh.HinhThucThanhToan;
            TextBox10.Text = dh.GhiChu.ToString();
            DropDownList1.SelectedIndex = dh.TinhTrang;
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            BUS_DonHang bdh = new BUS_DonHang();
            if (TextBox7.Text != null)
            {
                //if ((dh.SoLuong != DropDownListSoLuong.SelectedIndex) || (dh.PhiGiaoHang != int.Parse(TextBox7.Text)) ||
                //   (dh.TinhTrangThanhToan != DropDownList3.SelectedIndex) ||
                //    (dh.HinhThucThanhToan != DropDownList2.SelectedIndex) ||
                //    (dh.TinhTrang != DropDownList1.SelectedIndex))
                //{                    
                    dh.MaDH = MaDH;
                    dh.SoLuong = DropDownListSoLuong.SelectedIndex;
                    dh.PhiGiaoHang = int.Parse(TextBox7.Text);
                    dh.TinhTrangThanhToan = DropDownList3.SelectedIndex;
                    dh.HinhThucThanhToan = DropDownList2.SelectedIndex;
                    dh.TinhTrang = DropDownList1.SelectedIndex;
                    dh.GhiChu = TextBox10.Text;
                    bool sua = bdh.AdUpdateDH(dh);
                    if (sua == true)
                    {
                        string url = "~/Account_Admin/QuanLyDDH/DDH_Sua.aspx?ma=" + MaDH;
                        Response.Redirect(url);
                    }
                    else
                    {
                        Label6.Text = "Thất bại";
                    }
                //}
                //else
                //{
                //    Label6.Text = "Không có gì thay đổi";
                //}
            }
            else
            {
                Label6.Text = "Phí giao hàng khác null";
            }
        }
    }
}